//
//  AutobotsBaseViewController.m
//  AutobotsPlugin
//
//  Created by 张志恒 on 16/9/1.
//  Copyright © 2016年 Autohome. All rights reserved.
//

#import "RTBaseViewController.h"

@interface RTBaseViewController ()

@property (nonatomic, strong) UIButton *backButton;

@end

@implementation RTBaseViewController

#pragma mark - life cylce

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self __initProperty];
    [self __initSubviews];
}
#pragma mark - event response
- (void)backButtonClicked:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - private method
- (void)__initProperty
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)__initSubviews
{
    RTNavigationBar *navigationBar = [[RTNavigationBar alloc] init];
    navigationBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 64);
    [self.view addSubview:navigationBar];
    self.rt_navigationBar = navigationBar;
    
    NSBundle *bundle = [NSBundle bundleForClass:[RTProgressHUD class]];
    NSURL *url = [bundle URLForResource:@"RTUIKit" withExtension:@"bundle"];
    NSBundle *imageBundle = [NSBundle bundleWithURL:url];
    NSString *path = [imageBundle pathForResource:@"nav_back" ofType:@"png"];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setBackgroundImage:[UIImage imageNamed:path] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [navigationBar addSubview:backButton];
    self.backButton = backButton;
}

- (void)setNavigationTitle:(NSString *)title
{
    self.rt_navigationBar.titleLabel.text = title;
}

- (void)setNavigationBackHidden:(BOOL)hidden
{
    self.backButton.hidden = hidden;
}

- (void)viewWillLayoutSubviews
{
    [self.view bringSubviewToFront:self.rt_navigationBar];
}

#pragma mark - setters and getters


@end
